package com.zyl.pts.service.serviceImpl;

import com.zyl.pts.domain.bean.IndexRecord;
import com.zyl.pts.domain.vo.DRVO.DRPageVO;
import com.zyl.pts.domain.vo.SourceVO.BatchQRInfoVO;
import com.zyl.pts.domain.vo.SourceVO.SourceInfoVO;
import com.zyl.pts.mapper.SourceMapper;
import com.zyl.pts.service.SourceService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: product_source
 * @Package: com.zyl.pts.service.serviceImpl
 * @ClassName: SourceServiceImpl
 * @Description TODO()
 * @Author 翟玉龙
 * @Date 2024/11/25-9:38
 */
@Service
public class SourceServiceImpl implements SourceService {
    private final SourceMapper sourceMapper;

    public SourceServiceImpl(SourceMapper sourceMapper) {
        this.sourceMapper = sourceMapper;
    }
    /**
     * 获取溯源信息
     * @param animalId 动物id
     * @return {@link SourceInfoVO }
     */
    @Override
    public SourceInfoVO getSourceInfo(String animalId) {
        SourceInfoVO sourceInfo = sourceMapper.selectSourceInfo(animalId);
        List<DRPageVO> list = sourceMapper.selectDRPageVO(animalId);
        BatchQRInfoVO batchQRInfo = sourceMapper.selectBatchQRInfo(sourceInfo.getAnimal().getABatchId());
        if(batchQRInfo.getQuarantineRegistration().get(0).getGrBatchId() == null) {
            batchQRInfo.setQuarantineRegistration(null);
        }
        List<IndexRecord> indexes = sourceMapper.selectIndexRecord(animalId);
        sourceInfo.setDiseaseRecords(list).setBatch(batchQRInfo).setIndexRecords(indexes);
        return sourceInfo;
    }
}
